<?php
$id = isset($_REQUEST['id']) ? trim($_REQUEST['id']): '';
  
$cj = new Changjing();
$cu = $cj->userinfo('','uid,name,sex',$sid);
$friendsid = $api->friends_get($cu['uid']);


switch($act){
	case 'manage':
		$cjlist = $db->select("SELECT * FROM ".DB_PRE."changjing ORDER BY id DESC LIMIT 10");
		break;
		
	case 'add':
		if ($submit){
			
		$payinfo = $api->cash_subgoldapple(CHANGJING_GAPPLE);
		if($payinfo['@attributes']['msg'] == 'A1003') message('金苹果余额不足，请充值后再添加！');
		
			$data = array_slice($_POST,0,-1);
			if($data['title']=='null') message('请输入标题！');
			if($data['changjing']=='null') message('请输入场景内容！');
			$juesearr = explode(" ", $data['juese1']);
			$n = count($juesearr);
			if($n<2 || $n>4) message('角色数量要在2个到4个之间！');
			
			$data['juese1'] = $juesearr[0];
			$data['juese2'] = $juesearr[1];
			$data['juese3'] = $juesearr[2];
			$data['juese4'] = $juesearr[3];

			$cj->newchangjing($data);
			$content = '你的朋友'.$cj->showusername($cu['uid']).'在【角色公园】创建了一个场景，快来看看吧？ 你可以在场景里面扮演角色哦...亲身体验当大明星的感觉~~赶快加入角色扮演中来吧~~';
			$urltitle = '马上进入';
			$url = SITE_URL.'index.php';
			//测试给自己发在线消息
			//$api->message_sendonline(3031283052,$content,$urltitle,$url);
			foreach ($friendsid['uid'] as $f) {
				$api->message_sendonline($f,$content,$urltitle,$url);
			}
			message('提交成功！请等待管理员审核！');
		}
		break;
		
		
	case 'show':
		if ($submit){
			$data['juese'] = $_POST['juese'];
			$data['content'] = $_POST['content'];
			$data['changjing'] = $_POST['changjing'];
			
			if($data['juese']=='null') message('请选择角色！');
			if($data['content']=='null') message('一个字也不说？');
			$cj->newduihua($data);
			$content = '你的朋友'.$cu['name'].'在【角色公园】场景【'.$cj->showchangjing($data['changjing']).'】扮演了一个角色，想知道吗？ 你想扮演什么呢？快来看看吧...';
			$urltitle = '马上进入';
			$url = SITE_URL.'index.php';
			//测试给自己发在线消息
			$api->message_sendonline(3031283052,$content,$urltitle,$url);
			foreach ($friendsid['uid'] as $f) {
				$api->message_sendonline($f,$content,$urltitle,$url);
			}
			message('提交成功！');
		}else{
			$cjshow = $db->get_one("SELECT * FROM ".DB_PRE."changjing WHERE id =$id");
			$cjduihua = $db->select("SELECT * FROM ".DB_PRE."duihua WHERE changjing = $id");
		}
		break;
}


include tpl($mod.'.'.$act);
?>